<template>
    <view class="box">
        <view class="bgImage">
            <!-- #ifndef H5 -->
            <uni-nav-bar dark fixed backgroundStyle="transparent" color="#121317" status-bar>
                <template slot="left" v-if="hasBeforePage">
                    <uni-icons type="arrow-left" color="#121317" size="24"></uni-icons>
                </template>
                <template>
                    <view class="nav_title">专升本报考通</view>
                </template>
                <!-- #ifndef MP -->
                <template slot="right">
                    <view class="title-right" @click.stop="_shareOpen">
                        <text class="iconfont icon-a-Frame1076" style="color: #007aff; font-size: 32rpx"></text>
                        <text class="text">分享</text>
                    </view>
                </template>
                <!-- #endif -->
            </uni-nav-bar>
            <!-- #endif -->

            <view class="content_box" :style="{ height: `calc( 100% - ${navBarHeight}px )` }">
                <view class="titleBox">
                    <view>专升本</view>
                    <view class="blue_text">报考数据</view>
                    <view>查询</view>
                </view>
                <view class="titleTips">全国各省市统招专升本考生提供最新考试数据查询工具</view>
                <view class="provinceBox" @click.stop="checkProvince = true">
                    <uni-icons type="location-filled" color="#FFFFFF" size="20"></uni-icons>
                    <view class="text province-name">{{ provinceInfo.province_name || '选择省份' }}</view>
                    <view class="text iconfont icon-a-Frame1085"></view>
                </view>
                <template v-if="list.length">
                    <view class="uls">
                        <view class="lis" v-for="(item, index) in list" :key="index" @click.stop="goDetail(item)">
                            <view class="lis-top">
                                <image v-if="item.url" :src="item.url" mode="widthFix" />
                                <text v-else class="iconfont" :class="[ item.icon ]"></text>
                                <view class="lis-title">{{ item.title || '' }}</view>
                            </view>
                            <view class="lis-desc">
                                {{ item.desc || '' }}
                            </view>
                        </view>
                    </view>
                    <view class="tips">
                        *由于各方面情况的不断调整与变化，提供的所有考试信息仅供参考，敬请考生以考试单位最新发布的正式信息为准；{{ provinceInfo.province_name }}省查询可报考专业功能数据仅供参考，具体请咨询相关单位。
                    </view>
                </template>
                <view class="default" v-if="!loading && !list.length">
                    <view class="img-box">
                        <image src="https://bicpic.baikewang.com/images/1646994256440.png" mode="widthFix"></image>
                        <view class="text">啊哦，当前省份正在全力搭建中~</view>
                    </view>
                </view>
            </view>

            <view class="footer">© 拜课网大数据实验室</view>

            <checkProvince :isLiscation="true" @_close="_close()" :isShow="checkProvince"></checkProvince>
        </view>
    </view>
</template>
<script>
import { mixin } from '@/static/js/mixin.js';
export default {
    mixins: [mixin],
    data() {
        return {
            //#ifndef MP
            hearderShow: false,
            //#endif
            //#ifdef MP
            hearderShow: true,
            //#endif
            hasBeforePage: false,
            // imgUrl: '',
            list: [],
            checkProvince: false,
            provinceInfo: {},
            loading: true
        };
    },
    computed: {
        // 导航条高度
        navBarHeight() {
            let that = this;
            let navHeight = 0;
            let navigationBarHeight = 0;
            // #ifndef H5
            // 状态栏高度
            let info = uni.getSystemInfoSync();
            let statusBarHeight = info.statusBarHeight + info.safeAreaInsets.top || 0;
            // #ifdef MP

            // 获取微信胶囊的位置信息 width,height,top,right,left,bottom
            const custom = uni.getMenuButtonBoundingClientRect();
            // 导航栏高度(标题栏高度) = 胶囊高度 + (顶部距离 - 状态栏高度) * 2
            navigationBarHeight = custom.height + (custom.top - statusBarHeight) * 2;
            // #endif

            // 总体高度 = 状态栏高度 + 导航栏高度
            navHeight = navigationBarHeight + statusBarHeight;
            // #endif
            return navHeight;
        }
    },
    methods: {
        _close() {
            let that = this;
            let obj = getApp().globalData.provinceLiscationInfo;
            that.checkProvince = false;
            if (that.provinceInfo.province_id === obj.province_id) return;
            that.provinceInfo = getApp().globalData.provinceLiscationInfo;
            that.getProvinceFeature();
        },
        goDetail(obj) {
            let that = this;
            if (!that.provinceInfo.province_id) {
                that.checkProvince = true;
                return;
            }
            if (!obj.jump_data.url) return;
            obj.provinceInfo = that.provinceInfo;
            uni.setStorageSync('searchDataInfo',obj);
            if(obj.openPage){
                that.applicationRewritingNavigateTo({
                    url: obj.jump_data.url
                });
            }else{
                that.applicationRewritingNavigateTo({
                    url: '/pages/applicationPage/listDisplayPage'
                })
            }

        },
        select(e) {
            let { item, index } = e;
            // console.log(item, index, '******');
        },
        _shareOpen() {
            this.$refs.share.open('bottom');
        },
        async checkProvinceInfo() {
            let that = this;
            let provinceInfo = uni.getStorageSync('provinceLiscationInfo')||{};
            let location = uni.getStorageSync('location');
            that.provinceInfo = getApp().globalData.provinceLiscationInfo = provinceInfo;
            uni.setStorageSync('provinceLiscationInfo', provinceInfo);
            if (!provinceInfo.province_id) {
                that.checkProvince = true;
                // await that.fnGetlocation();
            }
            await that.getProvinceFeature();
        },
        // 定位省份功能
        fnGetlocation() {
            let that = this;
            uni.showLoading({
                title: '正在获取定位...',
                mask: true
            });
            uni.getLocation({
                type: 'wgs84',
                geocode: true,
                success: function (res) { },
                complete: async (info) => {
                    let location = `${info.latitude},${info.longitude}`;
                    let { code, data } = await that.$application_api.getLocationInfo({ location: location });
                    uni.hideLoading();
                    if (code != 0) {
                        uni.showToast({
                            icon: 'none',
                            title: '定位失败，请手动选择省份'
                        });
                        return;
                    }
                    uni.setStorageSync('provinceInfo', data);
                    uni.setStorageSync('location', data);
                    that.provinceInfo = getApp().globalData.provinceInfo = data;
                }
            });
        },
        // 获取省份功能点
        async getProvinceFeature() {
            let that = this;
            that.loading = true;
            that.list = [];
            let { code, data } = await that.$application_api.getProvinceFeature();
            that.loading = false;
            if (code != 0) return;
            that.list = data || [];
        }
    },
    mounted() {
        let pages = getCurrentPages(); //当前页
        let beforePage = pages[pages.length - 2]; //上个页面
        this.hasBeforePage = !!beforePage;
        this.checkProvince = false;
        this.checkProvinceInfo();
    },
    onShow(){
        uni.removeStorageSync('searchDataInfo');
    }
};
</script>

<style lang="scss" scoped>
.box {
    width: 100vw;
    height: 100vh;
    overflow: hidden;
    background: linear-gradient( 180deg, #FFFFFF 0%, #F4F5F7 100%);
}

.bgImage{
    width: 100vw;
    height: 100vh;
    overflow: hidden;
    background-image: url('https://bicpic.baikewang.com/images/picBed/2024/06/14/1718334203128_88@3x.png');
    background-repeat: no-repeat;
    background-size: 100% auto;
    background-position: 0 0;
}

.content_box {
    width: 100vw;
    overflow-y: auto;
    box-sizing: border-box;
    padding: 26rpx 36rpx 88rpx;

    .titleBox {
        width: 100%;
        display: flex;
        align-items: center;
        justify-content: flex-start;
        font-weight: 900;
        font-size: 68rpx;
        color: #111E4A;

        .blue_text {
            background: linear-gradient(180deg, #0052D9 0%, #007AFF 100%);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
        }
    }

    .titleTips {
        margin-top: 2rpx;
        font-weight: 400;
        font-size: $font-size-D;
        color: #6D7998;
    }

    .provinceBox{
        margin-top: 38rpx;
        display: inline-flex;
        width: max-content;
        height: max-content;
        padding: 12rpx 20rpx;
        box-sizing: border-box;
        background: $primary-btn-bg;
        border-radius: 20rpx;
        justify-content: flex-start;
        align-items: flex-end;
        .text{
            font-weight: 500;
            font-size: $font-size-C;
            color: $font-color-main-B;

            &.province-name{
                margin-left: 8rpx;
                margin-right: 10rpx;
            }

            &.iconfont{
                color: #D9D9D9;
                font-size: 20rpx;
            }
        }
    }

    .uls{
        width: 100%;
        margin-top: 67rpx;
        display: grid;
        grid-gap: 22rpx 10rpx;
        grid-template-areas: ". .";

        .lis{
            width: 100%;
            min-height: 164rpx;
            padding: 32rpx 16rpx 26rpx 20rpx;
            box-sizing: border-box;
            background-color: #ffffff;
            border-radius: 20rpx;
            // margin-bottom: 21rpx;
            .lis-top{
                width: 100%;
                display: flex;
                align-items: center;
                justify-content: flex-start;
                .lis-title{
                    margin-left: 10rpx;
                    font-weight: 700;
                    font-size: $font-size-F;
                    color: $font-color-main-A;
                }
                image {
                    width: 40rpx;
                    height: 40rpx;
                }
            }

            .lis-desc{
                margin-top: 28rpx;
                font-weight: 400;
                font-size: 24rpx;
                color: #5E6873;
            }

            &:nth-of-type(2n){
                margin-left: 10rpx;
            }
        }
    }

    .tips{
        margin-top: 40rpx;
        font-weight: 400;
        font-size: $font-size-E;
        color: #BABBBC;
        // letter-spacing: 2rpx;
        line-height: $font-size-E-line-height;
    }

    .default {
        width: 100%;
        height: 50vh;
        background-color: #ffffff;
        border-radius: 20rpx;
        margin: 40rpx auto;
    }
}

.footer {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100vw;
    text-align: center;
    font-weight: 400;
    font-size: $font-size-E;
    color: $font-color-main-A;
    padding: 25rpx 0;
    box-sizing: border-box;
}
</style>
